
function connect(dbName="demo"){
    const mongoose = require('mongoose');
    // console.log(mongoose);


    // 连接数据库 -> demo
    mongoose.connect("mongodb://localhost:27017/"+dbName, {useNewUrlParser:true,useUnifiedTopology:true })
    // mongoose.set('strictQuery',false)


    // 这种也可以看数据库是否连接成功
    mongoose.connection.on('connected', () => console.log('数据库连接成功'));
    mongoose.connection.on('error', () => console.log('数据库连接异常'));
    mongoose.connection.on('disconnectied', () => console.log('数据库连接断开'));

}

module.exports = connect;